package com.fengycx.diyevents.listener;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.fengycx.diyevents.PayOrderEvent;
import com.fengycx.templeate.GTPushTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

@Component
public class PayOrderEventListener implements ApplicationListener<PayOrderEvent> {

    @Autowired
    private GTPushTemplate gtPushTemplate;

    @Override
    public void onApplicationEvent(PayOrderEvent source) {
        JSONObject entries = JSONUtil.parseObj(source);
        String orderNo = entries.getStr("orderNo");
        String payUserId = entries.getStr("payUserId");

        //把个推消息发送给用户 ，最后一个参数应该是别名才对 TODO
        gtPushTemplate.pushSingleAlias("order",orderNo,payUserId);


    }
}
